package cn.wolfcode.wolf2w.redis.util;

import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;

/**
 * redis操作key统一管理工具类
 * 约定:一个key 对应一个枚举实例
 * 1:key的维护
 * 2:key有效性维护
 *
 */
@Getter
public enum RedisKeys {

    //攻略顶key
    STRATEGY_THUMBSUP("strategy_thumbsup",-1L),
    //攻略收藏key
    USER_FAVOR("user_favor",-1L),
    //vo对象key用来封装点赞,访问数...数据
    //-1约定,不过时
    STRATEGY_STATIS_VO("strategy_statis_vo",-1L),
    //短信验证码,存储时间时间5分钟
    VERIFY_CODE("verify_code", Consts.VERIFY_CODE_VAI_TIME*60L),
    //token,存活时间30分钟
    USER_TOKEN("user_token",Consts.USER_INFO_TOKEN_VAI_TIME*60L);

    //前缀
    private String prefix;
    //时间
    private Long time;

    private RedisKeys(String prefix, Long time) {
        this.prefix = prefix;
        this.time = time;
    }

    public String join(String ... values) {
        StringBuilder sb = new StringBuilder(50);
        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":").append(value);
        }
        return sb.toString();
    }

}
